﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PersonaLibrary.ViewModel.OrganizationsViewModel
{
    public class SelectAddressViewModel : EditableItemViewModel<Data.Organization, View.OrganizationView.SelectAddressDialog>
    {
        public SelectAddressViewModel(Data.Organization org)
            : base()
        {
            Departments = new Data.LinqToDbDataContext().Departments.Where(x => x.OrganizationId == org.Id).ToList();
            EditableItem = org;
        }

        public Data.Department SelectedDepartment { set; get; }

        public List<Data.Department> Departments { set; get; }

        public override void Commit()
        {
            EditableItem.Legaladdress = SelectedDepartment.Address;
            base.Commit();
        }

        public override bool CanCommit()
        {
            return SelectedDepartment != null;
        }
    }
}
